package com.shierke.Ume.ui.adapter.Match

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.shierke.Ume.R
import com.shierke.Ume.util.click
import kotlinx.android.synthetic.main.item_match.view.*
import javax.microedition.khronos.opengles.GL
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator
import android.graphics.Color.parseColor
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator
import android.content.Context
import android.graphics.Color
import com.shierke.Ume.ui.activity.explore.ExploreUserPrincipalActivity
import net.lucode.hackware.magicindicator.buildins.circlenavigator.CircleNavigator


/**
 * Create by Ybx
 * on 2020-10-19
 * Desribe:
 */
class HomeMatchAdapter(var datas: ArrayList<ArrayList<Int>>) :
    RecyclerView.Adapter<HomeMatchAdapter.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {

        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_match, parent, false)

        return ViewHolder(view)


    }

    override fun getItemCount() = datas.size


    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.onBind(datas[position], position)
    }


    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        private var selectIndex = 0

        fun onBind(arr: ArrayList<Int>, position: Int) {
            with(itemView) {


                val circleNavigator = CircleNavigator(context)
                circleNavigator.circleCount = arr.size
                circleNavigator.circleColor = Color.WHITE
                magic_indicator.navigator = circleNavigator



                Glide.with(context).load(arr[selectIndex]).into(imagev)


//                circleNavigator.onPageSelected(3)

                leftTv.click {
                    if (selectIndex > 0) {
                        selectIndex -= 1


                        circleNavigator.onPageSelected(selectIndex)
                        circleNavigator.notifyDataSetChanged()

                        Glide.with(context).load(arr[selectIndex]).into(imagev)

                    }
                }


                rightTv.click {

                    if (selectIndex < arr.size - 1) {
                        selectIndex += 1
                        Glide.with(context).load(arr[selectIndex]).into(imagev)

                        circleNavigator.onPageSelected(selectIndex)
                        circleNavigator.notifyDataSetChanged()

                    }
                }


                bottomTv.click {
                    ExploreUserPrincipalActivity.startActivity(context)
                }
            }
        }
    }


}